#!/usr/bin/env bash

set -eo pipefail

rm -rf /tmp/release
mkdir -p /tmp/release
cp clj-kondo /tmp/release

VERSION=$(cat resources/CLJ_KONDO_VERSION)

if [[ "$CLJ_KONDO_PLATFORM" = "linux" && "$CLJ_KONDO_ARCH" = "amd64" ]]; then
    jar="target/clj-kondo-$VERSION-standalone.jar"
    bb release-artifact "$jar"
    cp "$jar" /tmp/release
fi

cd /tmp/release

## release binary as zip archive

arch=${CLJ_KONDO_ARCH:-amd64}

if [ "$CLJ_KONDO_STATIC" = "true" ] && [ "$CLJ_KONDO_ARCH" != "aarch64" ]; then
    arch="static-$arch"
fi

archive="clj-kondo-$VERSION-$CLJ_KONDO_PLATFORM-$arch.zip"

zip "$archive" clj-kondo

cd -

bb release-artifact "/tmp/release/$archive"

## cleanup

cd /tmp/release
rm clj-kondo
